/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package backup

import (
	"github.com/rs/zerolog/log"
	"github.com/spf13/cobra"
	"satellite/app/backup"
)

// createCmd represents the createCmd command
var createCmd = &cobra.Command{
	Use:   "create",
	Short: "创建mgr的backup资源",
	Long:  `创建mgr的backup资源`,
	Args:  Args,
	Run: func(cmd *cobra.Command, args []string) {
		if createOption.Cluster == "" {
			log.Warn().Msg("cluster is required")
			return
		}
		if createOption.Secret == "" {
			log.Warn().Msg("secret is required")
			return
		}
		if createOption.Type != "full" && createOption.Type != "incr" {
			log.Warn().Msg("type is invalid")
			return
		}
		runner := backup.NewCreate(createOption).WithBase(base)
		err := runner.Run()
		if err != nil {
			log.Warn().Err(err).Send()
			return
		}
	},
}
var createOption = new(backup.CreateOption)

func init() {
	backupCmd.AddCommand(createCmd)
	createCmd.Flags().BoolVarP(&createOption.Preserving, "preserving", "p", false, "保留实例")
	createCmd.Flags().StringVarP(&createOption.Cluster, "cluster", "c", "", "")
	createCmd.Flags().StringVarP(&createOption.Type, "type", "t", "full", "备份类型,可选: [full,incr]")
	createCmd.Flags().StringVarP(&createOption.Way, "way", "w", "manual", "备份方式,可选: [manual,scheduled,compatible,deprecated]")
	createCmd.Flags().StringVarP(&createOption.Secret, "secret", "s", "", "")
	createCmd.Flags().StringVarP(&createOption.Endpoint, "endpoint", "e", "", "")
	createCmd.Flags().StringVarP(&createOption.Region, "region", "r", "", "")
	createCmd.Flags().StringVarP(&createOption.Bucket, "bucket", "b", "", "")
	createCmd.Flags().StringArrayVarP(&createOption.Databases, "databases", "d", nil, "")
}
